import 'dart:math';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/extension/date_string_extension.dart';
import 'package:tiktokadult/hj_page/pre_sale/pre_sale_provider.dart';
import 'package:tiktokadult/hj_page/user_center_page/widget/gradient_text.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

class UserChargeView extends StatelessWidget {
  final bool isFromCoin; // true: 来源金币充值, vip时间为灰色
  const UserChargeView({super.key, this.isFromCoin = false});

  @override
  Widget build(BuildContext context) {
    return Consumer<GlobalStore>(
      builder: (_, provider, __) {
        return Row(
          children: [
            NetworkImageLoader(
              imageUrl: provider.meInfo?.portrait ?? '',
              width: 60,
              height: 60,
              borderRadius: 30,
            ),
            12.sizeBoxW,
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      provider.meInfo == null
                          ? '未知'
                          : provider.meInfo?.name?.substring(0, min(provider.meInfo?.name?.length ?? 0, 9)) ?? '',
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(
                        fontSize: 18,
                        color: Colors.white,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    12.sizeBoxW,
                    Image.asset(
                      provider.isVIP() ? 'is_vip.png'.mineImgPath : 'no_vip.png'.mineImgPath,
                      width: 24,
                    ),
                  ],
                ),
                4.sizeBoxH,
                globalStore.isVIP()
                    ? Consumer<PreSaleProvider>(
                        builder: (context, provider, child) {
                          if (isFromCoin) {
                            return Text(
                              '到期时间:${globalStore.meInfo?.vipExpireDate?.utcTimeSToYMDString()}',
                              style: TextStyle(
                                color: Color(0xff989898),
                                fontSize: 12,
                              ),
                            );
                          } else {
                            return GradientText(
                              '到期时间:${globalStore.meInfo?.vipExpireDate?.utcTimeSToYMDString()}',
                              fontSize: 12,
                            );
                          }
                        },
                      )
                    : Text(
                        '您还不是会员 开通会员 畅享特权',
                        style: TextStyle(
                          color: Color(0xff989898),
                          fontSize: 12,
                        ),
                      ),
              ],
            )
          ],
        ).paddingSymmetric(horizontal: 16);
      },
    );
  }
}
